package ooday04;

public class Test {
    public static void main(String[] args) {
        /*
        //向上造型(多态)  第2
        Master master = new Master();
        Dog dog = new Dog("小白",3,"白");
        Fish fish = new Fish("小美",4,"粉红");
        Chick chick = new Chick("花花",2,"灰");
        master.feed(dog);//在传参的同时，系统自动做了向上造型
        master.feed(fish);
        master.feed(chick);
         */

        //向上造型(多态)  第1
        //Animal animals = new Animal();//抽象类不能被实例化
        Animal[] animals = new Animal[5];
        animals[0] = new Dog("小白",3,"白");
        animals[1] = new Dog("小黑",2,"黑");
        animals[2] = new Fish("小美",4,"粉红");
        animals[3] = new Fish("小翠",1,"黑");
        animals[4] = new Chick("花花",2,"灰");
        for (int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if (animals[i] instanceof Dog){
                Dog dog = (Dog)animals[i];
                dog.lookHome();
            }
            if (animals[i] instanceof Chick){
                Chick chick = (Chick)animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Swim){
                Swim s = (Swim) animals[i];
                s.swim();
            }
        }
    }
}


/*
Dog[] dog = new Dog[3];
        dog[0] = new Dog("小白",3,"白");
        dog[1] = new Dog("小黑",2,"黑");
        dog[2] = new Dog("小红",1,"红");
        for (int i=0;i<dog.length;i++){
            System.out.println(dog[i].name);
            dog[i].drink();
            dog[i].eat();
            dog[i].swim();
            dog[i].lookHome();
        }

        Chick[] chick = new Chick[2];
        chick[0] = new Chick("花花",2,"灰");
        chick[1] = new Chick("小翠",1,"黑");
        for (int i=0;i<chick.length;i++){
            System.out.println(chick[i].name);
            chick[i].drink();
            chick[i].eat();
            chick[i].layEggs();
        }

        Fish[] fish = new Fish[4];
        fish[0] = new Fish("小金",2,"金");
        fish[1] = new Fish("小甜",1,"翠绿");
        fish[2] = new Fish("小兰",6,"黄");
        fish[3] = new Fish("小美",4,"粉红");
        for (int i=0;i<fish.length;i++){
            System.out.println(fish[i].name);
            fish[i].drink();
            fish[i].swim();
            fish[i].eat();
        }
 */